//
//  WPRightManagerViewController.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/4.
//  Copyright © 2016年 HuaYiSoftware. All rights reserved.
//

#import "WPRightManagerViewController.h"
#import "WPDIYSegment.h"
#import "WPRightManageFooterView.h"
#import "WPRightManageHeaderView.h"
#import "WPRightManageTableViewCell.h"

static NSString *const kUITableViewCellIdentifier = @"cellIdentifier";

@interface WPRightManagerViewController ()<UITableViewDataSource, UITableViewDelegate, WPRightManageFooterViewDelegate, WPRightManageTableCellDelegate>
@property (nonatomic, strong) WPDIYSegment * segment;/**< 自定义分段控件 */
@property (nonatomic, strong) UILabel * noDataLabel;/**< 无数据提示 */
@property (nonatomic, strong) UITableView * rightTableView;/**< 权益列表 */ //表头表尾
@property (nonatomic, strong) NSMutableArray * rightManageArr;/**< 权益管理数据源 */
@property (nonatomic, assign) BOOL isContract;/**< 收缩 */
- (void)initializeDataSource; /**< 初始化数据源 */
- (void)initializeUserInterface; /**< 初始化用户界面 */
- (void)refreshData;/**< 刷新数据 */


@end

@implementation WPRightManagerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeDataSource];
    [self initializeUserInterface];
}
#pragma mark - init
- (void)initializeDataSource {
    self.rightManageArr = [NSMutableArray arrayWithCapacity:0];
    NSArray * arr1 = @[@"1231231232132131", @"4000", @"5张", @"成都省体育馆", @"当前至2016-04-23"];
    NSArray * arr2 = @[@"A1-F2", @"800"];
    NSMutableArray * arr3 = [NSMutableArray array];
    for (int i = 0; i< 5; i++) {
        [arr3 addObject:arr2];
    }
    NSArray * arr = @[arr1, arr3];
    [_rightManageArr addObject:arr];
    
}
- (void)initializeUserInterface {
    [self.view addSubview:self.segment];
    [_segment setSegmentOriginPoint:CGPointMake(0, navBar_Fheight)];
    [self.view addSubview:self.rightTableView];
}
#pragma mark - 刷新数据
- (void)refreshData {
    
}
#pragma mark - 协议UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _rightManageArr.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _isContract ? 0: [_rightManageArr[section][1] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WPRightManageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kUITableViewCellIdentifier];
    if (!cell) {
        cell = [[WPRightManageTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kUITableViewCellIdentifier];
    }
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell refreshDataWithArr:_rightManageArr[indexPath.section][1][indexPath.row]];
    return cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 110*DHFlexibleHorizontalMutiplier();
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 175*DHFlexibleHorizontalMutiplier();
}
//设置每一行高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 30*DHFlexibleHorizontalMutiplier();
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    WPRightManageHeaderView *headView = [[WPRightManageHeaderView alloc]init];
    [headView refreshDataWithArr:_rightManageArr[section][0]];
    return headView;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    WPRightManageFooterView * view = [[WPRightManageFooterView alloc]init];
    view.delegate = self;
    return view;
}
#pragma mark - private protocol
- (void)actionOnEditBtn {
    
}
- (void)actionOnTransBtn {
    
}
-(void)actionOnSpreadBtn:(BOOL)isContract{
    self.isContract = isContract;
  [_rightTableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
}
- (void)configFootView {
    WPRightManageFooterView * view = [[WPRightManageFooterView alloc]init];
    view.delegate = self;
}
#pragma mark - getter
- (WPDIYSegment *)segment {
    if (!_segment) {
        _segment = ({
            WPDIYSegment * seg = [[WPDIYSegment alloc]initWithTitles:@[@"可用", @"失效"]];
            seg;
        });
    }
    return _segment;
}
- (UITableView *)rightTableView {
    if (!_rightTableView) {
        _rightTableView = ({
            UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), 105*DHFlexibleHorizontalMutiplier(), 300*DHFlexibleHorizontalMutiplier(), SCREEN_SIZE.height - 105*DHFlexibleHorizontalMutiplier()) style:UITableViewStyleGrouped];
            tableview.dataSource = self;
            tableview.delegate = self;
            tableview.tableFooterView = [UIView new];
            tableview.pagingEnabled = NO;
            tableview.bounces = NO;
            tableview.layer.cornerRadius = 5*DHFlexibleHorizontalMutiplier();
            tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
            tableview;
        });
    }
    return _rightTableView;
}
@end
